<template>
	<view>
		<view class="time">
			<tm-pickers :default-value="selected"  :list="list1" @confirm='startTime'>
				<tm-button >取车时间{{stime}}</tm-button>
			</tm-pickers>
			<tm-pickers :default-value="selected"  :list="list2" @confirm='endTime'>
				<tm-button>换车时间{{etime}}</tm-button>
			</tm-pickers>
		</view>

		<tm-calendarView mode='rang' color="bg-gradient-pink-accent" @confirm='changeEnd' :bing-start.sync='rangstarttime' :time-start='srangetime' :bing-end.sync='rangendtime'></tm-calendarView>

	</view>
</template>

<script>
	export default {
		// 
		onLoad(ref) {
			let date = new Date()
			let y = date.getFullYear()
			let m =date.getMonth()+1
			let d = date.getDate()
			let xq =date.getDay()
			this.srangetime= y+'-'+m+'-'+d
			
			this.rangstarttime =  y+'-'+m+'-'+d
			this.rangendtime = y+'-'+m+'-'+(d+2)
			
			this.stime=ref.stime
			this.etime = ref.etime
			console.log(this.rangstarttime,this.rangendtime);
		},
		 mounted() {

		 },
		data() {
			return {
				srangetime:'',
				rangstarttime:'',
				rangendtime:'',
				list1:['10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00'],
				list2:['10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00'],
				stime:'',
				etime:'',
			}
		},
		methods: {
			changeEnd(e){
				// console.log(e);
				let syear = e[0].month+'月'+e[0].day+'日'
				// console.log(syear);
				 let eyear= e[1].month+'月'+e[1].day+'日'
				 let starttime =e[0].year+'-' +e[0].month+'-'+e[0].day
				 let  endtime =e[1].year+'-' + e[1].month+'-'+e[1].day
				 let days = this.getDaysBetween(starttime,endtime)
				 
				 console.log('111', starttime,endtime,days);
				uni.$emit('gettime',this.stime,this.etime,syear,eyear,e[0].year,e[1].year,e[0].week_text,e[1].week_text,starttime,endtime,days)
				uni.navigateBack({
					delta:1
				})
			},
			startTime(e){
				// console.log(e[0].data);
				this.stime = e[0].data
			},
			endTime(e){
				// console.log(e[0].data);
				this.etime = e[0].data
			},
		getDaysBetween(date1,date2){
			    let  startDate = Date.parse(date1);
			    let  endDate = Date.parse(date2);
			    if (startDate>endDate){
			        return '0';
			    }
			    if (startDate==endDate){
			        return '1';
			    }
			     let days=(endDate - startDate)/(1*24*60*60*1000);
			    return  (days+1) ;
			}
		}
	}
</script>

<style lang="scss" scoped>
.time{
	display: flex;
	justify-content: space-evenly;
}
</style>
